/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __ibmmq_get_data_by_bytes.c                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/08 by jikw                                 */
/*******************************************************************/
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frct_comm.h"
#include "../../../src/module/ibmmq/config.h"
#include "../test_ibmmq_comm.h"
#include <apmtest_comm.h>
#include <frreport_opt.h>
#include <ibmmq/cnaps2.h>
//#include <ibmmq/ibmmq_analysis.h>
#include <ibmmq/ibmmq_core.h>
//#include <ibmmq/ibmmq_comm.h>
//#include <ibmmq/ibmmq_charset.h>
//#include "../../../src/exec/framework/frreport_session_mng.c"

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

extern int __ibmmq_get_data_by_bytes(Frbyte_Packet *p_st_data
                                   , unsigned int ui_bytes
                                   , char **pp_out);

static void case1(void)
{
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_bytes = 4;
    char *p_out = NULL;
    int i_ret = FR_SUCC;

    i_ret = __ibmmq_get_data_by_bytes(p_st_data, ui_bytes, &p_out);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void case2(void)
{
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_bytes = 4;
    int i_ret = FR_SUCC;

    p_st_data = (Frbyte_Packet *)frmalloc(sizeof(Frbyte_Packet));
    memset(p_st_data, 0x00, sizeof(Frbyte_Packet));

    i_ret = __ibmmq_get_data_by_bytes(p_st_data, ui_bytes, NULL);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    frfree(p_st_data);

    return;
}

static void case3(void)
{
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_bytes = 0;
    char *p_out = NULL;
    int i_ret = FR_SUCC;

    p_st_data = (Frbyte_Packet *)frmalloc(sizeof(Frbyte_Packet));
    memset(p_st_data, 0x00, sizeof(Frbyte_Packet));

    i_ret = __ibmmq_get_data_by_bytes(p_st_data, ui_bytes, &p_out);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    frfree(p_st_data);

    return;
}

static void case4(void)
{
    Frbyte_Packet *p_st_data = NULL;
    unsigned int ui_bytes = 7;
    char *p_data = (char *)"\x54\x53\x48\x20\x00\x00\x01\xEC";
    char *p_out = NULL;
    int i_ret = FR_SUCC;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_data, 8);

    i_ret = __ibmmq_get_data_by_bytes(p_st_data, ui_bytes, &p_out);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    int i = 0;
    for (; i < 7; i++)
    {
        printf("[%02X]\n", p_out[i]);
    }

    bytebuff_free(&p_st_data);
    frfree(p_out);

    return;
}

int add_suite__ibmmq_get_data_by_bytes(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __ibmmq_get_data_by_bytes()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL ||
        CU_add_test(pSuite, "case4", case4) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
